package com.pharmacy.mapper;


import com.pharmacy.annotation.AutoFill;
import com.pharmacy.dto.CategoriesSelectDto;
import com.pharmacy.dto.CategoriesUpdateDto;
import com.pharmacy.entity.Categories;
import com.pharmacy.enumeration.OperationType;
import com.pharmacy.vo.CategoriesSelectVo;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface CategoriesMapper {

    /**
     * 添加分类
     */
    @Insert("insert into categories(name, created_at, updated_at, created_by, updated_by)" +
            " VALUES (#{name},#{createdAt},#{updatedAt},#{createdBy},#{updatedBy})")
    void addCategories(Categories categories);

    /**
     * 删除分类
     */
    @Delete("delete from categories where id = #{id}")
    void deleteCategories(int id);

    /**
     * 查询所有分类
     */

    List<CategoriesSelectVo> allSelectCategories(CategoriesSelectDto categoriesSelectDto);


    /**
     * 修改分类
     */
    @AutoFill(value = OperationType.UPDATE)
    @Update("update categories set name = #{name}, updated_at = #{updatedAt}, updated_by = #{updatedBy} where id = #{id}" )
    void updateCategories(Categories categories);

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Select("select * from categories where id = #{id}")
    Categories getById(Integer id);
}
